<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  function keys(obj) {
    if (obj !== Object(obj)) throw new TypeError('Invalid object');
    var keys = [];
    for (var key in obj) if (Object.hasOwnProperty.call(obj, key)) keys[keys.length] = key;
    return keys;
  }

  try {
    keys('obj')
  } catch (error) {
    console.error(error)
  }

</script>
</body>
</html>